/**
 * Created by 李雅荣 on 2017/7/27.
 */
class Drag{
    //属性
    constructor(){
        this.oDiv=document.querySelector('div');
    }
    //方法
    show(){
        var div=this.oDiv;
        div.onmousedown=function(ev){
            var ev=ev||event;
            //鼠标距oDiv的距离
            var disX=ev.clientX-div.offsetLeft;
            var disY=ev.clientY-div.offsetTop;
            document.onmousemove=function(ev){
                var ev=ev||event;
                //oDiv距浏览器边缘的距离
                var x = ev.clientX-disX;
                var y = ev.clientY-disY;
                div.style.left = x+"px";
                div.style.top = y+"px";

            }
            document.onmouseup=function(){
                document.onmouseup=null;
                document.onmousemove=null;
            }
            return false;
        }
    }
}


window.onload=function(){
    var drag=new Drag();
    drag.show();
}
